package com.zdkj.subway.st.util;

/**
 * @ProjectName: zdkj
 * @Package: com.zdkj.subway.st.util
 * @ClassName: SequenceUtils
 * @Description:
 * @Author: kangjian
 * @CreateDate: 2020/2/7 11:46
 * @Version: 1.0
 */
public class SequenceUtils {
    static final int DEFAULT_LENGTH = 3;
    static final int DEFAULT_LENGTH_4 = 4;

    public static String getSequence(long seq) {
        String str = String.valueOf(seq);
        int len = str.length();
        if (len >= DEFAULT_LENGTH) {// 取决于业务规模,应该不会到达3
            return str;
        }
        int rest = DEFAULT_LENGTH - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rest; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }

    public static String getSequence4(long seq) {
        String str = String.valueOf(seq);
        int len = str.length();
        if (len >= DEFAULT_LENGTH_4) {// 取决于业务规模,暂时定4
            return str;
        }
        int rest = DEFAULT_LENGTH_4 - len;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < rest; i++) {
            sb.append('0');
        }
        sb.append(str);
        return sb.toString();
    }
}
